Call an API in javascript without refreshing page